home *** CD-ROM | disk | FTP | other *** search
- unit Frunit4;
- { PC Plus sample Delphi program. A simple French verb conjugator - mark 4 }
- { This now deals with regular ER, IR and RE verbs. It illustrates the use }
- { of standard Pascal procedures }
- { }
- { Note the use of WITH }
- { in With Form1.ListBox1.Items do }
- { }
- { Also the 'shortcut' way of calling the JePlusStem function }
- { i.e Instead of declaring an intermediate string variable, 's' }
- { and then using the expressions: }
- { s := JePlusStem(vStem); }
- { Add( s + 'e'); }
- { this has all been done in one go: }
- { Add(JePlusStem(vStem) + 'e'); }
-
-
-
- interface
-
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls;
-
- type
- TForm1 = class(TForm)
- ListBox1: TListBox;
- Edit1: TEdit;
- Label1: TLabel;
- Button1: TButton;
- procedure Button1Click(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
-
- var
- Form1: TForm1;
-
- implementation
-
- {$R *.DFM}
- procedure ConjugateALLER;
- begin
- With Form1.ListBox1.Items do
- begin
- Clear;
- Add('Je vais');
- Add('Tu vas');
- Add('Il va');
- Add('Elle va');
- Add('Nous allons');
- Add('Vous allez');
- Add('Ils vont');
- Add('Elles vont');
- end;
- end;
-
- procedure ConjugateAVOIR;
- begin
- With Form1.ListBox1.Items do
- begin
- Clear;
- Add('J''ai');
- Add('Tu as');
- Add('Il a');
- Add('Elle a');
- Add('Nous avons');
- Add('Vous avez');
- Add('Ils ont');
- Add('Elles ont');
- end;
- end;
-
- procedure ConjugateETRE;
- begin
- With Form1.ListBox1.Items do
- begin
- Clear;
- Add('Je suis');
- Add('Tu es');
- Add('Il est');
- Add('Elle est');
- Add('Nous sommes');
- Add('Vous etes');
- Add('Ils sont');
- Add('Elles sont');
- end;
- end;
-
- function JePlusStem( vStem : string ) : string;
- { Function checks to see if a vowel begins the verb. If so }
- { it retuns "J'" plus verb stem. Else, it reurns "Je " plus verbStem }
- Const { declare vowels as a set of characters }
- vowels : set of char = ['a','e','i','o','u','y'];
- begin { see if 1st letter of vStem is in the set named 'vowels' }
- if vStem[1] in vowels then
- JePlusStem := 'J''' + vStem
- else
- JePlusStem := 'Je ' + vStem;
- end;
-
-
- procedure ConjugateERverb( vStem : string );
- begin
- with Form1.ListBox1.Items do
- begin
- Clear;
- { call the JePlusStem function to return the Je form }
- Add(JePlusStem(vStem) + 'e');
- Add('Tu ' + vStem + 'es' );
- Add('Il ' + vStem + 'e' );
- Add('Elle ' + vStem + 'e' );
- Add('Nous ' + vStem + 'ons' );
- Add('Vous ' + vStem + 'ez' );
- Add('Ils ' + vStem + 'ent');
- Add('Elles ' + vStem + 'ent');
- end;
- end;
-
- procedure ConjugateREverb( vStem : string );
- begin
- with Form1.ListBox1.Items do
- begin
- Clear;
- Add(JePlusStem(vStem) + 's');
- Add('Tu ' + vStem + 's' );
- Add('Il ' + vStem );
- Add('Elle ' + vStem );
- Add('Nous ' + vStem + 'ons' );
- Add('Vous ' + vStem + 'ez' );
- Add('Ils ' + vStem + 'ent');
- Add('Elles ' + vStem + 'ent');
- end;
- end;
-
- procedure ConjugateIRverb( vStem : string );
- begin
- with Form1.ListBox1.Items do
- begin
- Clear;
- Add(JePlusStem(vStem) + 'is');
- Add('Tu ' + vStem + 'is' );
- Add('Il ' + vStem + 'it' );
- Add('Elle ' + vStem + 'it' );
- Add('Nous ' + vStem + 'issons' );
- Add('Vous ' + vStem + 'issez' );
- Add('Ils ' + vStem + 'issent');
- Add('Elles ' + vStem + 'issent');
- end;
- end;
-
- procedure TForm1.Button1Click(Sender: TObject);
- var { --- Declare 3 string variables --- }
- verb, { the verb specified by the user }
- verbStem, { the verb minus its 2-letter ending }
- verbEnd : string; { the 2-letter ending }
- begin
- verb := LowerCase( Edit1.Text );{ make text lower case }
- { check that the user has entered something... }
- if verb = '' then
- Caption := 'You must enter a verb!'
- else
- begin {... if so, then }
- { find the stem and the ending of the verb }
- verbStem := copy( verb, 1, length(verb)-2 );
- verbEnd := copy( verb, length(verb) -1, 2 );
- Caption := 'This is an ' + verbEnd + ' verb.';
- { find type of verb and call appropriate proc }
- { ---- check for IRREGULAR verbs ------------ }
- if verb = 'aller' then
- conjugateALLER
- else if verb = 'etre' then
- conjugateETRE
- else if verb = 'avoir' then
- conjugateAVOIR
- { ------ then deal with REGULAR verbs -------- }
- else if verbEnd = 'er' then
- ConjugateERverb( verbStem )
- else if verbEnd = 're' then
- ConjugateREverb( verbStem )
- else if verbEnd = 'ir' then
- ConjugateIRverb( verbStem )
- else { if this isn't an ER, RE or IR verb, show error msg... }
- Caption := 'You must enter an ER, RE or IR verb!';
- end;
- end;
-
- end.
-